import Vue from 'vue'
import VueRouter from 'vue-router'
//引入Login组件
import Login from '../views/Login.vue'
import Home from '../views/Home.vue'
import Register from "../views/Register";

Vue.use(VueRouter)
const routes = [
    {
        path: "/register",
        component: Register
    },
    {
        path: "/",
        component: Home,
    },
    {
        path: "/login",
        component: Login
    },
]


const router = new VueRouter({
    mode: 'history', //后端支持可开
    // base: '/blog',
    scrollBehavior: () => ({
        y: 0
    }),
    routes:routes
})
//导航监控器:
/*
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location,onResolve,onReject){
  if(onResolve || onReject) return originalPush.call(this,location,onResolve,onReject)
  return originalPush.call(this,location).catch(err => err)
}


router.beforeEach((to,from,next)=>{
  //to将要访问
  //from从哪访问
  //next接着干  重定向到url上next（）继续访问到tor路径
  if(to.path=='/login') return next();
  //获取user
  const userFlag= window.sessionStorage.getItem("user");//取出用户
  if(!userFlag) return  next('/login');
  next();//符合要求

})
*/

export default router
